//
//  FirCirCommentDataSource.m
//  tcpoctest
//
//  Created by gump on 4/16/13.
//  Copyright (c) 2013 gump. All rights reserved.
//

#import "FirCirCommentDataSource.h"
#import "FirCirSendCommentInfo.h"
#import "FirCirCommentInfo.h"

@implementation FirCirCommentDataSource

-(id)init
{
    self = [super init];
    if (self != nil) {
        fircirCommentDic = [[NSMutableDictionary alloc] init];
        pthread_mutex_init(&commentmutex, 0);
        sendinfo = [[FirCirSendCommentInfo alloc] init];
    }
    
    return self;
}

-(void)SetCommentDic:(NSString *)newsID withObject:(FirCirCommentInfo *)showarr
{
    pthread_mutex_lock(&commentmutex);
    
    [fircirCommentDic setObject:showarr forKey:newsID];
    
    pthread_mutex_unlock(&commentmutex);
}

-(void)RemoveAllCommentDic
{
    pthread_mutex_lock(&commentmutex);
    
    [fircirCommentDic removeAllObjects];
    
    pthread_mutex_unlock(&commentmutex);
}

-(void)SetCommentSendInfo:(NSString *)mail
                withNewID:(NSString *)newid
              withSpeakTo:(NSString *)speakto
{
    pthread_mutex_lock(&commentmutex);
    
    sendinfo.mail = mail;
    sendinfo.newid = newid;
    sendinfo.speakto = speakto;
    
    pthread_mutex_unlock(&commentmutex);
}

-(void)SetCSInfoIndex:(int)index  withContent:(NSString *)content
{
    pthread_mutex_lock(&commentmutex);
    
    sendinfo.istindex = index;
    sendinfo.content = content;
    
    pthread_mutex_unlock(&commentmutex);
}

-(FirCirSendCommentInfo *)SendCommentInfo
{
    FirCirSendCommentInfo *fcscinfo = nil;
    
    pthread_mutex_lock(&commentmutex);
    
    fcscinfo = sendinfo;
    
    pthread_mutex_unlock(&commentmutex);
    
    return fcscinfo;
}

-(FirCirCommentInfo *)getCommentInfoByID:(NSString *)commentid
{
    FirCirCommentInfo *fccinfo = nil;
    
    pthread_mutex_lock(&commentmutex);
    
    fccinfo = [fircirCommentDic objectForKey:commentid];
    
    pthread_mutex_unlock(&commentmutex);
    
    return fccinfo;
}

-(void)RemoveCommentInfoByID:(NSString *)commentid
{
    pthread_mutex_lock(&commentmutex);
    
    [fircirCommentDic removeObjectForKey:commentid];
    
    pthread_mutex_unlock(&commentmutex);
}


@end
